
const initialState = {
  pageNo: 1, // 当前分页
  curIndex: '', // 当前模板 id
  tempData: {}, // 当前拖拽的图表的数据
  formInfo: [], // 当前视图的所有图表信息
};

export const types = {
  SET_PAGENO: 'grid/SET_PAGENO',
  SET_CUR_INDEX: 'grid/SET_CUR_INDEX',
  SET_TEMP_DATA: 'grid/SET_TEMP_DATA',
  SET_FORM_INFO: 'grid/SET_FORM_INFO'
};

export const actions = {
  setpageNo: val => ({ type: types.SET_PAGENO, value: val }),
  handleCurIndex: val => ({ type: types.SET_CUR_INDEX, value: val }),
  setTempData: val => ({ type: types.SET_TEMP_DATA, payload: val }),
  setFormInfo: val => ({ type: types.SET_FORM_INFO, payload: val })
};

// eslint-disable-next-line complexity
export default function gridReducer(state = initialState, action) {
  switch (action.type) {
    case types.SET_PAGENO:
      return { ...state, pageNo: action.value };
    case types.SET_CUR_INDEX:
      return { ...state, curIndex: action.value };
    case types.SET_TEMP_DATA:
      return { ...state, tempData: action.payload };
    case types.SET_FORM_INFO:
      return { ...state, formInfo: action.payload };
    default:
      return state;
  }
}
